package com.homework;

import java.io.File;
import java.util.Scanner;

/**
 * @author xiyu
 * @version 1.0
 * @date 2025/3/28 17:28
 * @description
 */
public class T2 {
    static long dirsize = 0;
    public static void main(String[] args) {
//        File dir = new File("D:\\file\\test\\dir1");
        Scanner input = new Scanner(System.in);
        System.out.println("请输入文件夹路径：");
        String Path = input.nextLine();
        File dir = new File(Path);

        if(dir.exists() && dir.isDirectory()){
            findsize(dir);
            System.out.println("文件夹的大小是:" + dirsize);
        }else{
            System.out.println("路径不存在");
        }

    }

    public static void findsize(File file){
        if(file.isDirectory()){
            File[] fs = file.listFiles();
            for(File f : fs){
                findsize(f);
            }
        }else{
            dirsize += file.length();
        }
    }

}
